package com.tma.demo;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class SimpleListActivity extends Activity 
    implements OnItemClickListener, OnItemLongClickListener {

    private static final String TAG = "SimpleListActivity";
    private ListView mListView;
    private ArrayAdapter<CharSequence> mAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple_list);

        mListView = (ListView) findViewById(R.id.lv_month);
        mAdapter = ArrayAdapter.createFromResource(this, R.array.months, android.R.layout.simple_list_item_1);
        mListView.setAdapter(mAdapter);

        mListView.setOnItemClickListener(this);
        mListView.setOnItemLongClickListener(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_array_adapter, menu);
        return true;
    }

    public boolean onItemLongClick(AdapterView<?> adapterView, View target,
            int position, long id) {
        // see layout definition of android.R.layout.simple_list_item_1
        TextView tv = (TextView) target;
        Log.i(TAG, "onItemLongClick: " + tv.getText().toString());
        Log.i(TAG, "onItemLongClick: position = " + position + "; id = " + id);
        Toast.makeText(this,
                "onItemLongClick: position = " + position + "; id = " + id,
                Toast.LENGTH_SHORT).show();
        return true;
    }

    public void onItemClick(AdapterView<?> adapterView, View target,
            int position, long id) {
        // see layout definition of android.R.layout.simple_list_item_1
        TextView tv = (TextView) target;
        Log.i(TAG, "onItemClick: " + tv.getText().toString());
        Log.i(TAG, "onItemClick: position = " + position + "; id = " + id);
        Toast.makeText(this,
                "onItemClick: position = " + position + "; id = " + id,
                Toast.LENGTH_SHORT).show();
    }
}
